var now = getNowFormatDateTime(); 
var username = sessionStorage.getItem("name");
var userid = sessionStorage.getItem("userId");
var repairid;
var _config ;
var flag =1;

$(document).ready(function(){
	$("#username").prepend(username);
	$("#now").prepend(getNowFormatDateTime());
	getInfo();
});
function getInfo(){
	 document.getElementById('data').innerHTML = "";
	$.ajax({
		url: "../../repair_info/getweixiu"
		,type:'post'
		,data:JSON.stringify({"userid":userid,"flag":flag})
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			var trStr;
			var operation ="";
			var operation2 ="";
			var flagname="";
			var classname="";
			for (var i = 0; i < res.data.length; i++) {
				if(res.data[i].flag == '1'){classname="orange";flagname='未接单'; operation = '<button type="button" style="background-color:#599EF8;color:white;width:40px;margin-top:1px" onclick = "jiedan(\''+res.data[i].repairid+'\')">接单</button>';}
				else if(res.data[i].flag == '21'){classname="orange";flagname='未开始';operation = '<button type="button" style="background-color:#599EF8;color:white;width:40px;margin-top:1px" onclick = "weixiu(\''+res.data[i].repairid+'\')">维修</button>';
																   operation2 = '<button type="button" style="background-color:#599EF8;color:white;width:40px;margin-top:1px" onclick = "paidan(\''+res.data[i].repairid+'\')">派单</button>';}
				else if(res.data[i].flag == '22'){classname="orange";flagname='已开始';operation = '<button type="button" style="background-color:#599EF8;color:white;width:40px;margin-top:1px" onclick = "weixiu(\''+res.data[i].repairid+'\')">维修</button>';}
				else if(res.data[i].flag == '3'){classname="orange";flagname='待确认';operation = '<button type="button" style="background-color:#599EF8;color:white;width:40px;margin-top:1px" onclick = "remind(\''+res.data[i].tel+'\')" >提醒</button>';}
				else if(res.data[i].flag == '4'){classname="orange";flagname='待评价';operation = '<button type="button" style="background-color:#599EF8;color:white;width:40px;margin-top:1px" onclick = "remindpj(\''+res.data[i].tel+'\')" >提醒</button>';}
				else {classname="orange";flagname='已完成';operation = '';}
					trStr += '<tr class="thin-border-bottom">'
							+'	<td onclick = "more(\''+res.data[i].repairid+'\',\''+res.data[i].flag+'\')" class="'+classname+'">'+res.data[i].shopcode+'</span></td>'
							+'	<td>'+res.data[i].repairtype+'</td>'//
							+'	<td>'+res.data[i].instruction+'</td>'
							+'	<td>'+res.data[i].repairdate.substring(0,10)+'</br>'+operation2+'</td>'
							+'	<td>'+flagname+'</br>'+operation+'</td>'
							+'</tr>'
					operation = "";operation2 = "";
			}
			$('#data').append(trStr);
			
			
		}
	});
}
function detail(repairid,flag){	
	var url;
	if(flag=='1'){
		url = "../../mobile_page/baoxiu/baoxiu_search?repairid="+repairid;//此处拼接内容
	}else if(flag=='2'){
		url = "../../mobile_page/baoxiu/baoxiu_search_free?repairid="+repairid;//此处拼接内容
	}
	window.location.href = url;
}	
function setshopname(){
	var shopcode = $('#shopcode').val();
	$('#shopname').val("");
	$.ajax({
			url: '../../repair_info/fillshopname'
			,type:'post'
			,dataType:'json'
			,contentType: "application/json; charset=utf-8"
			,data:JSON.stringify({'shopcode':shopcode})  
			,success: function(res){
				if(res.data.field != undefined){
					$('#shopname').val(res.data.field.deptname);
				}
			}
	});
}
function search_time(time){
	$(".child1")[0].style.backgroundColor="#599EF8";
	$(".child2")[0].style.backgroundColor="#599EF8";
	$(".child3")[0].style.backgroundColor="#599EF8";
	$(".child4")[0].style.backgroundColor="#599EF8";
	$(".child5")[0].style.backgroundColor="#599EF8";
	$(".child"+time)[0].style.backgroundColor="#BEBEBE";
	flag=time;
	getInfo();
	if(flag==1){
		$("#repairdate")[0].style.display="";
		$("#acceptdate")[0].style.display="none";
	}else{
		$("#repairdate")[0].style.display="none";
		$("#acceptdate")[0].style.display="";
	}
}
function jiedan(repairid){
	$.ajax({
		url: '../../repair_info/jiedan'
		,type:'post'
		,dataType:'json'
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({'repairid':repairid,'flag':21,"accept":userid})  
		,success: function(res){
			search_time(2);
		}
	});
}
function more(repairid,flag){

		var url= "../../mobile_page/weixiu/weixiu_search?repairid="+repairid+'&flag='+flag;//此处拼接内容
		window.location.href = url;
	
}
function paidan(repairid){
	var url= "../../mobile_page/weixiu/weixiu_paidan?repairid="+repairid;//此处拼接内容
	window.location.href = url;
}
function weixiu(repairid){
	var url= "../../mobile_page/weixiu/weixiu_weixiu?repairid="+repairid;//此处拼接内容
	window.location.href = url;
}
function remind(tel){
	var userid="";
	$.ajax({
		url: '../../repair_info/getuserid'
		,type:'post'
		,dataType:'json'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"phone":tel})  
		,success: function(res){
			console.log(res);
			userid = res.data[0].userid
		}
	});
	$.ajax({
		url: '../../repair_info/remind'
		,type:'post'
		,dataType:'json'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"agentid":"1430137971","userid":userid,"url":"http://123.56.177.178:8383/unite_platform/mobile_page/index_baoxiu?v="+Math.random(),"title":"确认提醒","text":"请及时确认"})  
		,success: function(res){
		}
	});
		layer.msg("操作成功",{time:1000},function(){
			location.reload();
	});
}
function remindpj(tel){
	var userid="";
	$.ajax({
		url: '../../repair_info/getuserid'
		,type:'post'
		,dataType:'json'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"phone":tel})  
		,success: function(res){
			userid = res.data[0].userid
		}
	});
	$.ajax({
		url: '../../repair_info/remind'
		,type:'post'
		,dataType:'json'
		,async: false
		,contentType: "application/json; charset=utf-8"
		,data:JSON.stringify({"agentid":"1430137971","userid":userid,"url":"http://123.56.177.178:8383/unite_platform/mobile_page/index_baoxiu?v="+Math.random(),"title":"评价提醒","text":"请及时进行评价"})  
		,success: function(res){
			
		}
	});
	layer.msg("操作成功",{time:1000},function(){
			location.reload();
	});
}